<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>电影管理</title>
<%@include file="/WEB-INF/jsps/common.jsp" %>
</head>
<script type="text/javascript">
$(function(){
	
	$("#shareVideoAdd").click(function(){
		$("#shareVideoDatagridDlg").dialog('open').dialog('center').dialog('setTitle','添加电影');
		$("#shareVideoDatagridForm").form('clear');
	});
	$("#shareVideoEdit").click(function(){
		alert("1111");	
		});
	$("#shareVideoDel").click(function(){
		var row =$("#shareVideoDatagrid").datagrid('getSelected');
		if(!row){
			$.messager.alert('温馨提示','请选择一行之后进行操作','error')
		}
		if(row){
			 $.messager.confirm('温馨提示','您确认删除该数据吗?',function(r){
                 if (r){
                	 
                	 $.get("shareVideo/del?id="+row.id,
                			 //删除成功与否，失败了给出提示信息 
                			  function(data){
                		 		if (data.success) {
                		 			 $.messager.alert('温馨提示','删除成功!',"info");
                		 			$("#shareVideoDatagrid").datagrid("reload");
								}else{
									 $.messager.alert('温馨提示',data.message,"error");
								}
                		 		
                			  }
                	 	,"json"
                	 );
                 }
             });
		}
		
		});
	$("#shareVideoRefresh").click(function(){
		$("#shareVideoDatagrid").datagrid("reload");
	});
	
	$("#shareVideoSave").click(function(){
		$("#loadimg").attr("hidden",false);
		 $('#shareVideoDatagridForm').form('submit',{
             url: "shareVideo/save",
             onSubmit: function(){
                 return $(this).form('validate');
             },
             success: function(result){
            	 try {
            	 //表单提交返回回来的Json字符串，要转换为Json对象
            		 var result = JSON.parse(result);
                     if (result.success){
                    	 $("#loadimg").attr("hidden",true);
                    	 //提示
                    	 $.messager.alert('温馨提示','操作成功!',"info");
                    	 //关闭对话框
                    	 $('#shareVideoDatagridDlg').dialog('close'); 
                    	 //刷新表格
     		 			 $("#shareVideoDatagrid").datagrid("reload");
                     } else {
                    	 //提示
                    	 $("#loadimg").attr("hidden",true);
                    	 $.messager.alert('温馨提示',result.message,"error");
                    	 //刷新表格--后台删除成功但是返回的数据格式有问题
     		 			 $("#shareVideoDatagrid").datagrid("reload");
                     }
					
				} catch (e) {
					 $("#loadimg").attr("hidden",true);
					$.messager.alert('温馨提示',"数据转换异常！"+e,"error");
				}
            	
             }
         });
	})
	$("#shareVideoCancel").click(function(){
		$('#shareVideoDatagridDlg').dialog('close');
		$("#shareVideoDatagrid").datagrid("reload");
	});
});
   function formatterimagePath(value,row,index){
	   if(value){
		   return "<img src='"+value+"'  width='50px' alt='没有图片'/>"
	   }
	   return "";
	   
   }
   function formattertype(value,row,index){
	   if(value==1){
		   return "宣传电影"
	   }
	   if(value==2){
		   return "喜剧小品"
	   }
	   if(value==3){
		   return "娱乐电影"
	   }
	   return "";
	   
   }
</script>
<body>

	<!-- 管理表格 -->
    <table  height="" id="shareVideoDatagrid" title="电影管理" class="easyui-datagrid" style="width:700px;height:250px"
            url="shareVideo/list"
            fit="true"
            toolbar="#shareVideoDatagridToolbar" 
            pagination="true"
            rownumbers="true" 
            fitColumns="true" 
            singleSelect="true">
        <thead>
            <tr>
                <th field="id" width="50" hidden="true">id</th>
                <th field="filmName" width="50" align="center">电影名称</th>
                <th field="imagePath" width="30" data-options="formatter:formatterimagePath" align="center">缩略图</th>
                <th field="path" width="50">路径电影</th>
                <th field="type" data-options="formatter:formattertype" width="50">电影类型</th>
            </tr>
        </thead>
    </table>
    <!-- 管理表格toolbar -->
     <div id="shareVideoDatagridToolbar">
     	<!-- 
     		data-cmd="shareVideoAdd" 
     		告诉同意监听要调用哪个方法
     	 -->
        <a id="shareVideoAdd" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" >添加电影</a>
        <a id="shareVideoDel" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除电影</a>
		<a id="shareVideoRefresh"  href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true">刷新</a>
        <div>
        <!--添加或者修改对话框  -->
         <div id="shareVideoDatagridDlg" class="easyui-dialog" style="width:400px"
            closed="true" buttons="#shareVideoDatagridDlgButtons">
        <form id="shareVideoDatagridForm" method="post" novalidate style="margin:0;padding:20px 50px" enctype="multipart/form-data" >
			<table>
 		 <tr>
			    <td>电影名称</td>
			   <td><input type="text"  class="easyui-textbox" name="filmName" required="true" style="width:100%"/></td>
		  </tr>
		  <tr>
		    <td>电影封面</td>
		   <td> <input class="easyui-filebox" name="filmImage" data-options="prompt:'请选择电影封面...',required:true"    style="width:100%"></td>
		  </tr>
		  <tr>
		    <td>上传电影</td>
		   <td> <input class="easyui-filebox" name="film" data-options="prompt:'请选择上传电影...'" required="true" style="width:100%"></td>
		  </tr>
		  <tr>
		    <td>电影类型</td>
		   <td>
			    <select  name ="filmType" class="easyui-combobox"  data-options="required:true" style="width:100% ">
				    <option value="1">宣传电影</option>
				    <option value="2" >喜剧小品</option>
				    <option value="3" selected>娱乐电影</option>
				</select>
			</td>
		  </tr>
		  <tr id="loadimg" hidden="ture">
		  <td >
		     上传中
		  </td>
		  <td>
		  <img  src="${pageContext.request.contextPath }/resources/images/load.gif"/>
		  </td>
		  
		  </tr>
</table>

        </form>
    </div>
    
     <!-- 添加或修改对话框按钮 -->
    <div id="shareVideoDatagridDlgButtons">
        <a id="shareVideoSave" href="javascript:void(0)" class="easyui-linkbutton " iconCls="icon-ok" style="width:90px">保存</a>
        <a id="shareVideoCancel" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" style="width:90px">取消</a>
    </div>
</body>
</html>